<template>
  <div style="width: 1200px;margin: 0 auto;min-height: 100vh;">
    <span style="display: flex;justify-content: space-between;padding-top: 10px;">
      
     <router-link to="/main/renshi/kaoqing/jiangchen/zhaunxiangjlsqd" style="">返回</router-link>
    <router-link to="/main/renshi/kaoqing/jiangchen/zhaunxiangjlsqd" style="">新增申请</router-link>
    </span>
    <h2>专项奖励申请列表</h2>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="employeeId" label="工号" width="120"></el-table-column>
      <el-table-column prop="name" label="姓名" width="120"></el-table-column>
      <el-table-column prop="departmentName" label="部门名称" width="120"></el-table-column>
      <el-table-column prop="position" label="职务" width="120"></el-table-column>
      <el-table-column prop="reason" label="奖励事由" width="calc(100% - 200)"></el-table-column>
      <el-table-column prop="rewardAmountSmall" label="奖励金额" width="120">
        <template slot-scope="scope">
          {{ scope.row.rewardAmountSmall.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column prop="fillDate" label="填表日期" width="120">
        <template slot-scope="scope">
          {{ formatDate(scope.row.fillDate) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleDetail(scope.row)">详情</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!-- 详情对话框 -->
    <el-dialog title="专项奖励申请详情" :visible.sync="dialogVisible" width="50%">
      <div v-if="detailData">
        <p><strong>工号：</strong>{{ detailData.employeeId }}</p>
        <p><strong>姓名：</strong>{{ detailData.name }}</p>
        <p><strong>部门名称：</strong>{{ detailData.departmentName }}</p>
        <p><strong>性别：</strong>{{ detailData.gender }}</p>
        <p><strong>职务：</strong>{{ detailData.position }}</p>
        <p><strong>入职日期：</strong>{{ formatDate(detailData.entryDate) }}</p>
        <p><strong>填表日期：</strong>{{ formatDate(detailData.fillDate) }}</p>
        <p><strong>奖励事由：</strong>{{ detailData.reason }}</p>
        <p><strong>奖励金额（小写）：</strong>{{ detailData.rewardAmountSmall }}</p>
        <p><strong>奖励金额（大写）：</strong>{{ detailData.rewardAmountCapital }}</p>
        <p><strong>部门经理意见：</strong>{{ detailData.managerOpinion }}</p>
        <p><strong>部门批示：</strong>{{ detailData.departmentOpinion }}</p>
        <p><strong>总经理意见：</strong>{{ detailData.generalManagerOpinion }}</p>
        <p><strong>企业管理部意见：</strong>{{ detailData.enterpriseManagementOpinion }}</p>
        <p><strong>总裁/董事长意见：</strong>{{ detailData.presidentOpinion }}</p>
        <p><strong>生效月份：</strong>{{ detailData.effectiveYear }}年{{ detailData.effectiveMonth }}月</p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getSpecialRewardApplyList, getSpecialRewardApplyDetail, deleteSpecialRewardApply } from '@/api/specialRewardApply';

export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      dialogVisible: false,
      detailData: null
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    async fetchData() {
      try {
        const response = await getSpecialRewardApplyList({
          current: this.currentPage,
          size: this.pageSize
        });
        this.tableData = response.data.records;
        this.total = response.data.total;
      } catch (error) {
        this.$message.error('获取数据失败：' + error.message);
      }
    },
    async handleDetail(row) {
      try {
        const response = await getSpecialRewardApplyDetail(row.id);
        this.detailData = response.data;
        this.dialogVisible = true;
      } catch (error) {
        this.$message.error('获取详情失败：' + error.message);
      }
    },
    async handleDelete(row) {
      try {
        await this.$confirm('确认删除该专项奖励申请？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        await deleteSpecialRewardApply(row.id);
        this.$message.success('删除成功');
        this.fetchData();
      } catch (error) {
        if (error !== 'cancel') {
          this.$message.error('删除失败：' + error.message);
        }
      }
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.fetchData();
    },
    formatDate(date) {
      if (!date) return '';
      return date.split('T')[0];
    }
  }
};
</script>

<style scoped>
.el-table {
  margin-top: 20px;
}
.el-pagination {
  margin-top: 20px;
  text-align: right;
}
</style> 